import { createApp } from 'vue'
import './style.css'
import './assets/font/iconfont.css'
import './assets/font/iconfont.js'

// 引用element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn'
import Cookies from 'js-cookie'

// 引入v-md-editor
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
// 预览组件
import VMdPreview from '@kangc/v-md-editor/lib/preview';
import '@kangc/v-md-editor/lib/style/preview.css';

// 代码高亮
import createHighlightLinesPlugin from '@kangc/v-md-editor/lib/plugins/highlight-lines/index';
import '@kangc/v-md-editor/lib/plugins/highlight-lines/highlight-lines.css';
// 引入代码行号
import createLineNumbertPlugin from '@kangc/v-md-editor/lib/plugins/line-number/index';

// 复制代码
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';

import Prism from 'prismjs';
// v-md-editor使用组件功能
VueMarkdownEditor.use(vuepressTheme, {
  Prism,
});
VueMarkdownEditor.use(createCopyCodePlugin());
VueMarkdownEditor.use(createHighlightLinesPlugin());
VueMarkdownEditor.use(createLineNumbertPlugin());
VMdPreview.use(vuepressTheme, {
  Prism,
});

import App from './App.vue'
const app = createApp(App)


import router from './router'
app.use(router)

import store from './store';
app.use(store);

// svg图标
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/svgicon'

// 分页组件
import Pagination from '@/components/Pagination'

//空状态
import empty from '@/components/empty/index.vue'
app.component("sy-empty", empty);

// 注册指令
import plugins from './plugins' // plugins
app.use(plugins)


//图片预览
import VueViewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
app.use(VueViewer);

//图片懒加载
import VueLazyLoad from 'vue-lazyload'
// 2.注册插件
app.use(VueLazyLoad, {
  preLoad: 1,
  // 懒加载默认加载图片
  loading: 'https://gw.alicdn.com/imgextra/i3/2200975635975/O1CN017P6CM91u0bMpfYuvT_!!2200975635975.jpg_Q75.jpg_.webp',
  // 加载失败后加载的图片
  error: 'https://gw.alicdn.com/imgextra/i3/2200975635975/O1CN017P6CM91u0bMpfYuvT_!!2200975635975.jpg_Q75.jpg_.webp',
  attempt: 1
})

import defaultSetting from "@/setting";
app.config.globalProperties.$setting = defaultSetting

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
  locale: locale,
  // 支持 large、default、small
  size: Cookies.get('size') || 'default'
})
app.use(elementIcons)
app.component('svg-icon', SvgIcon)
app.component('Pagination', Pagination)
app.use(VueMarkdownEditor); // 使用VueMarkdownEditor
app.use(VMdPreview); // 预览组件
//全局导入el图标
import * as components from '@element-plus/icons-vue'
for (const key in components) {
    const componentConfig = components[key];
    app.component(componentConfig.name, componentConfig);
}


app.mount('#app')
